package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/nursing_project")
@Api(tags="护理页项目")
public class NursingProjectController extends BaseController{

    @Autowired
    NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> queryPage(
            String name,
            Integer status,
            Integer pageNum,
            Integer pageSize
    ){
        PageResponse<NursingProjectVo> pageResult=nursingProjectService.queryPage(name,status,pageNum,pageSize);
        return success(pageResult);
    }

    @PostMapping
    @ApiOperation("新增服务")
    public ResponseResult addNursing(
            @RequestBody NursingProjectDto nursingProjectDto
            ){
        nursingProjectService.addNursing(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除服务")
    public ResponseResult deleteNursing(
            @ApiParam(value="删除服务的id")
           @PathVariable("id")Integer id
            ){
        nursingProjectService.deleteNursing(id);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value="根据id查询服务",notes="回显")
    public ResponseResult<NursingProjectVo> getNursingById(
            @ApiParam(value="删除服务的id")
            @PathVariable("id")Integer id
    ){
        NursingProjectVo nursingProjectVo= nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }
    @PutMapping
    @ApiOperation("更改服务")
    public ResponseResult updateNursing(

            @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursing(nursingProjectDto);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有")
    public ResponseResult<List<NursingProjectVo>> getAllProject(){
       List<NursingProjectVo>nursingProjectVoList= nursingProjectService.getAll();
        return success(nursingProjectVoList);
    }
}
